package com.hfzy.ihk.web.linkcall.support.filter;

import com.hfzy.ihk.web.linkcall.context.Context;
import com.hfzy.ihk.web.linkcall.context.ContextIntf;
import com.hfzy.ihk.web.linkcall.context.impl.WebContextIntfImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.filter.GenericFilterBean;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Order(1)
public class SessionFilter extends GenericFilterBean {
    private final static Logger logger= LoggerFactory.getLogger(SessionFilter.class);
    @Autowired
    ContextIntf contextIntf;
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        String path = req.getServletPath();
        Context.contextIntf = contextIntf;
        Context.contextIntf.setRequest(req);
        chain.doFilter(request,response);

        return;
    }
}
